import cv2
import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":
    # Canny edge detection
    img_gray = cv2.imread("../images/test_write.jpg", cv2.IMREAD_GRAYSCALE)
    img = cv2.imread("../images/Camera_A_1.jpg", cv2.IMREAD_COLOR)
    # Noise reduction

    # Compute image gradient
    # Non-maximum suppression
    # Double threshold filtering
    '''    
    result_01 = cv2.Canny(img_gray, 80, 150)
    result_02 = cv2.Canny(img_gray, 50, 100)
    result_03 = np.hstack((result_01, result_02))
    cv2.imshow("Canny", result_03)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    '''
    gray_contour = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    ret, thresh = cv2.threshold(gray_contour, 63, 255, cv2.THRESH_BINARY)
    contours, hiearchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    draw_img = img.copy()
    res = cv2.drawContours(draw_img, contours, -1, (0, 0, 255), 2)
    cv2.imshow("res", res)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
